<?php 
include("files/php/global.php"); 
printHeader();
session_start();
?>

	<head>
		
                <script type="text/javascript" src="files/js/mootools.js"></script>
                <script type="text/javascript" src="files/js/moocheck.js"></script>
                <link media="screen" type="text/css" href="style/form.css" rel="stylesheet" />
                <link rel="stylesheet" type="text/css" href="style/button.css" />
                <link rel="stylesheet" href="style/readme_files/screensmall.css" type="text/css" media="screen" />
                <link rel="stylesheet" type="text/css" href="style/themes/blue/style.css"/> 
                <style>
                    
                    .button{
                        text-align:left;
                        margin-top: -8px;
                    }

                    .reset{

                        text-align:left;
                        margin-top: -36px;
                        margin-left: 105px;
                    }
  

                </style>
        </head>
    
 <?php
    global $ADMIN;
    if(isset($_POST['submit'])) 
    {
        $mysql = new Db();
        $mysql->connect();
        for($i=1;$i<16;$i++)
        {
            $i_sms = $i."_sms";
            $i_fax = $i."_fax";
            $i_email = $i."_email";
            $alrma_id=$i;
            $query="update alarm_table set ";//send_sms=1 where alarm_id=1;";
            if(isset($_POST[$i_sms])) 
                $query.="send_sms = 1 ";
            else
                $query.="send_sms = 0 ";
            
            if(isset($_POST[$i_fax])  ) 
                $query.=",send_fax = 1 ";
            else
                $query.=",send_fax = 0 ";
            
            if(isset($_POST[$i_email]) )
                $query.=",send_email = 1 ";
            else
                $query.=",send_email = 0 ";
            
            $query.="where alarm_id=".$i.";";
            
            $mysql->execute($query);
           // echo "\n$query\n";
        }
        $mysql->disconnettiDB();
    }
    
?>
         
<body >
    <div id="abilitaAllarmi">
    <form  action="AbilitaAllarmi.php" class="formular" id="formular" method="post">
          
          <fieldset><legend>Elenco Allarmi disponibili</legend>
        <table cellspacing="1" class="tablesorter">
			<thead>
				<tr>
					<th ></th>
                                        <th ></th>
                                        <th>Invio Allarme SMS</th>
                                        <th>Invio Allarme FAX</th>
                                        <th >Invio Allarme EMAIL</th>
				</tr>
                        </thead>
                        <tfoot>
                            <tr>
                                    <td colspan="4" class="rounded-foot-left"><em>Elenco allarmi del sistema</em></td>
                                    <td class="rounded-foot-right">&nbsp;</td>
                            </tr>
                        </tfoot>
			<tbody>                            
        
	
    	<?php 
             loadDataAllarm();
             $option='DISABLED';
             if($ADMIN == $_SESSION['u_name'])
                 $option='';
             foreach($LISTA_ALLARMI as $i => $tel)
             {
                    print("<tr>");
                    print("<td >$i</td>");
                    print("<td ><label>$tel[3]</label></td>");
                    if($tel[0])
                        print("<td ><div class='section demo'><label><input type=\"checkbox\" name=\"".$i."_sms\" value=\"1\" checked=\"checked\" $option /></label>  </div></td>\n");
                    else
                        print("<td ><div class='section demo'><label><input type=\"checkbox\" name=\"".$i."_sms\" value=\"1\" id=\"ch_emails\" $option /></label></div></td>\n");
                    if($tel[1])
                        print("<td ><div class='section demo'><label><input type=\"checkbox\" name=\"".$i."_fax\" value=\"1\" checked=\"checked\" $option /></label></div></td>\n");
                    else
                        print("<td ><div class='section demo'><label><input type=\"checkbox\" name=\"".$i."_fax\" value=\"1\" id=\"ch_emails\"  $option /></label></div></td>\n");
                    if($tel[2])
                        print("<td ><div class='section demo'><label><input type=\"checkbox\" name=\"".$i."_email\" value=\"1\" checked=\"checked\" $option /></label></div></td>\n");
                    else
                        print("<td ><div class='section demo'><label><input type=\"checkbox\" name=\"".$i."_email\" value=\"1\" id=\"ch_emails\" $option /></label></div></td>\n");
						
             }
            ?> 
                  </tbody>
		</table>
               <?php if($ADMIN == $_SESSION['u_name'])
               {
               ?>
              <div class="button"> 
                                    <input type="submit" name="submit" value="Salva" class="buttonview" /> 
                                </div>
                                <div class="reset"> 
                                    <input type="reset"  value="Reset" class="buttonglosalva" /> 			
                                </div>
<!--              
                    <input type="submit" name="formSubmit" value="Submit" />
                    <input type="reset" value="Reset Form" style='margin:1em;height:2.5em;background:#222;float:right;color:#fff'/>-->
          <?php } ?>        
          </fieldset>
                </form>
    </div>
       </body>
</html>